package com.example.mq.controller.base;

import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Supplier;

public class BaseController {

    public <T> Map<String, Object> precessData(Supplier<T> supplier, BiConsumer<Map<String, Object>, Exception> biConsumer){
        Map<String, Object> map = new HashMap<>();
        try {
            T data = supplier.get();
            map.put("data", data.toString());
            map.put("code", 200);
            return map;
        } catch (Exception e) {
            biConsumer.accept(map, e);
            return map;
        }

    }

    public <T> void processException(Map<String, Object> map, Exception e){
        map.put("message",e.getMessage());
        map.put("code", 500);
    }
}
